//
//  YTAdvertVC.m
//  CllForIOS
//
//  Created by qiyun on 2018/3/9.
//  Copyright © 2018年 aRui. All rights reserved.
//

#import "YTAdvertVC.h"
#import "YTTabBarController.h"
@interface YTAdvertVC ()<UIScrollViewDelegate>
@property(strong,nonatomic)UIScrollView *myScrollView;
@property (strong, nonatomic) NSArray *picArray;
@end

@implementation YTAdvertVC

- (BOOL)prefersStatusBarHidden {
    
    return YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.picArray=@[@"advert1",@"advert2",@"advert3"];
    if (iPhoneX) {
        self.picArray=@[@"iphoneX_advert1",@"iphoneX_advert2",@"iphoneX_advert3"];
    }
    [self setupScrollView];
}
- (void)setupScrollView{

    UIScrollView*myScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];

    myScrollView.contentSize = CGSizeMake(SCREEN_W * self.picArray.count,SCREEN_H);
    myScrollView.pagingEnabled = YES;                                         //分页时候自动跳转到边界
    myScrollView.showsHorizontalScrollIndicator = NO;                         //控制水平方向是否滚动
    myScrollView.showsVerticalScrollIndicator = NO;                           //控制垂直方向是否滚动
    myScrollView.directionalLockEnabled = YES;                                //是否锁定跟踪滚动方向
    myScrollView.alwaysBounceVertical = NO;                                   //是否垂直回弹
    myScrollView.bounces = NO;                                                //是否有回弹效果
    myScrollView.scrollsToTop = NO;                                           //是否滚动到TOP
    myScrollView.clipsToBounds = YES;                                         //修剪边界
    myScrollView.scrollEnabled = YES;
    myScrollView.delegate = self;
    
    self.myScrollView=myScrollView;
    [self.view addSubview:myScrollView];
    
    [self loadimage];
}
-(void)loadimage{
    for (int i = 0; i < self.picArray.count;i++) {
        UIImageView*imageview=[[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_W*i, 0, SCREEN_W, SCREEN_H)];
        imageview.image = [UIImage imageNamed:self.picArray[i]] ;
        if (i== self.picArray.count -1) {
            imageview .userInteractionEnabled = YES;
            UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
            //手指数
            singleFingerOne.numberOfTouchesRequired = 1;
            //点击次数
            singleFingerOne.numberOfTapsRequired = 1;
            //增加事件者响应者
            [imageview  addGestureRecognizer:singleFingerOne];
        }
        [self.myScrollView addSubview:imageview ];
    }
    
}
- (void)handleSwipeGesture:(UIGestureRecognizer*)sender{
    [self dismissViewControllerAnimated:1 completion:nil];
}
@end
